package com.joysuch.wwyt.api.dataaccess;

import com.google.common.collect.Lists;
import com.joysuch.wwyt.api.dataaccess.bean.ThreeCardInBean;
import com.joysuch.wwyt.bp.entity.BpEmergencyExerciseRecord;
import com.joysuch.wwyt.bp.entity.BpProductionFacility;
import com.joysuch.wwyt.bp.entity.BpWorkSafetyCert;
import com.joysuch.wwyt.bp.entity.contractor.BpContractor;
import com.joysuch.wwyt.bp.repository.BpContractorDao;
import com.joysuch.wwyt.bp.repository.BpEmergencyExerciseRecordDao;
import com.joysuch.wwyt.bp.repository.BpProductionFacilityDao;
import com.joysuch.wwyt.bp.repository.BpWorkSafetyCertDao;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.entity.EduTrainningRecord;
import com.joysuch.wwyt.edu.repository.EduTrainningRecordDao;
import com.joysuch.wwyt.risk.entity.RiskDistrict;
import com.joysuch.wwyt.risk.entity.RiskPoint;
import com.joysuch.wwyt.risk.repository.RiskDistrictDao;
import com.joysuch.wwyt.risk.repository.RiskPointDao;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author ZhangDong
 * @Date 2020/8/17 14:27
 */
@RestController
@Api(tags = "/data-access 数据接入")
@RequestMapping("/bp/data-access")
public class DataAccessController {

    @Autowired
    private DataAccessService dataAccessService;
    @Autowired
    private BpProductionFacilityDao facilityDao;
    @Autowired
    private EduTrainningRecordDao trainningRecordDao;
    @Autowired
    private BpEmergencyExerciseRecordDao exerciseRecordDao;
    @Autowired
    private RiskDistrictDao riskDistrictDao;
    @Autowired
    private RiskPointDao riskPointDao;
    @Autowired
    private BpContractorDao bpContractorDao;
    @Autowired
    private BpWorkSafetyCertDao certDao;
    @Autowired
    private EduTrainningRecordDao eduTrainningRecordDao;

    /**
     * 1,2,8,13,14,15,17,18,21,22,  9
     *
     * @return
     */

    @GetMapping("test")
    public ResultBean test() {
        return ResultBean.success(dataAccessService.getCode());
    }

    @GetMapping("safe/device")
    public ResultBean safeDevice() {
        BpProductionFacility one = facilityDao.getOne(380L);
        ArrayList<BpProductionFacility> bpProductionFacilities = Lists.newArrayList(one);
        dataAccessService.safeDevice(bpProductionFacilities);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("train/record")
    public ResultBean trainRecord() {
        EduTrainningRecord record = trainningRecordDao.getOne(16L);
        dataAccessService.trainRecord(record);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("emergency/exercisee/record")
    public ResultBean emergencyExerciseRecord() {
        //BpEmergencyExerciseRecord record = exerciseRecordDao.getOne(47L);
        BpEmergencyExerciseRecord record = new BpEmergencyExerciseRecord();
        record.setId(47L);
        record.setEpId(26L);
        dataAccessService.emergencyExerciseRecord(record);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("risk/district")
    public ResultBean riskDistrict() {
        //dataAccessService.riskDistrict();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("risk/area")
    public ResultBean riskArea() {
        List<Long> list = Lists.newArrayList(421L);
        List<RiskDistrict> riskDistrictList = riskDistrictDao.findAllById(list);
        dataAccessService.riskArea(riskDistrictList);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("risk/point")
    public ResultBean riskPoint() {
        List<Long> list = Lists.newArrayList(3830L);
        List<RiskPoint> riskPointList = riskPointDao.findAllById(list);
        dataAccessService.riskPoint(riskPointList);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("three/card")
    public ResultBean threeCard() {
        List<ThreeCardInBean> list = Lists.newArrayList();
        ThreeCardInBean bean = new ThreeCardInBean();
        bean.setCode("YJ00000099");
        bean.setRiskDistrictId(419L);
        bean.setPicName("危险有害因素应知卡");
        bean.setPicId(445L);
        list.add(bean);
        dataAccessService.threeCard(list);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("contractor")
    public ResultBean contractor() {
        BpContractor contractor = bpContractorDao.getOne(98L);
        dataAccessService.contractor(contractor);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("work/apply")
    public ResultBean workApply() {
        BpWorkSafetyCert cert = certDao.getOne(669L);
        dataAccessService.workApply(cert);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("scene/train")
    public ResultBean sceneTrain() {
        EduTrainningRecord one = eduTrainningRecordDao.getOne(16L);
        dataAccessService.sceneTrain(one);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("work/level")
    public ResultBean workLevel() {
        dataAccessService.workLevel(new HashMap<>());
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("safe/input")
    public ResultBean safeInput() {
        //dataAccessService.safeInput();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("hidden/danger")
    public ResultBean hiddenDanger() {
      //  dataAccessService.hiddenDangerReport();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("law/standard")
    public ResultBean lawStandard() {
        //dataAccessService.lawStandardReport();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("factory/over/alarm")
    public ResultBean factoryOveralarm() {
        dataAccessService.factoryOveralarm();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("leader/duty/table")
    public ResultBean leaderDutyTable() {
        //dataAccessService.leaderDutyTable();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("leader/duty/record")
    public ResultBean leaderDutyRecord() {
        //dataAccessService.leaderDutyRecord();
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("change/apply")
    public ResultBean changeApply() {
        //dataAccessService.changeApply();
        return ResultBean.defaultSuccessResult();
    }

}
